<template>
    <div>
        <div slot="title" class="wly-dialog-title">
            <span class="header-line-vertical"/>
        </div>
            <el-form :model="form" :inline="true" label-width="110px">
                <el-row>
                    <el-form-item label="角色" prop="name">
                        <el-input size="mini" :maxlength="60" v-model="form.name"></el-input>
                    </el-form-item>
                </el-row>
            </el-form>
        <div slot="footer" class="dialog-footer center">
            <el-button size="mini" @click="cancel">取 消</el-button>
            <el-button size="mini" type="primary" @click="roleMaintain">确 定</el-button>
        </div>

    </div>
</template>

<script>
    import ajax from '@api/ajax'
    import {ROLE_MAINTAIN} from '@api/url'

    export default {
        name: 'RoleForm',
        data () {
            return {
                dialogVisible: false,
                Ostatus: '',
                form: {
                    name: ''
                }
            }
        },
        methods: {
            // 获取调用页面传入的数据
            showForm (data, status) {
                debugger
                this.form = JSON.parse(JSON.stringify(data))
                console.info(this.form)
                this.Ostatus = status
                this.dialogVisible = true
            },
            // 新增或者编辑调用的方法
            roleMaintain () {
                if (this.Ostatus === 'add') {
                    this.form.optMode = 'A'
                    this.form.status = '0'
                }
                if (this.Ostatus === 'edit') {
                    this.form.optMode = 'U'
                }
                ajax.post(ROLE_MAINTAIN, this.form).then(res => {
                    this.dialogVisible = false
                    this.$emit('saved', this.dialogVisible)
                }).catch(err => {
                    console.error('查询发生错误！', err)
                })
            },
            cancel () {
                this.dialogVisible = false
                this.$emit('saved', this.dialogVisible)
            }

        },
        mounted () {

        }

    }
</script>

<style scoped>

</style>
